class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """

        kh={')':'(',']':'[','}':'{'}

        if s=='':
            return True
        
        temp=''
        stack=''

        while s:
            temp=s[0]
            s=s[1:]
            if temp in kh.values():
                stack=stack+temp
            else:
                if len(stack)>0:
                    if kh[temp]==stack[-1]:
                        stack=stack[:-1]
                    else:
                        return False
                else:
                    return False
        if len(stack)==0:
            return True
        else:
            return False
            
                
s=Solution()
s.isValid("[])")
     
